<?php
include_once('/var/www/html/new/com.inc.php');

if(!isset($_SESSION['sid'])) exit('{"status":"fail","msg":"登陆过期","code":0}');


$memberSID = $_SESSION['sid'];
$memberID  = $_SESSION['memberID'];

switch(trim($_REQUEST['action'])){
	
	// 获取Key
	case 'auth_information':
		$DockingMode = $_REQUEST['set_conf'] + 0;  //  0 去哪儿  1 美团  2 百度直达
		$response = array('status'=>'success', 'signkey'=>'', 'supplierIdentity'=>'', 'cooperation_way'=>'');
		$sql = "select supplierIdentity,signkey,cooperation_way from uu_qunar_use where fid=$memberSID and DockingMode=$DockingMode and supplierIdentity<>'' limit 1";
		$GLOBALS['le']->query($sql);
		if(($dbRow = $GLOBALS['le']->fetch_assoc())) $response = array_merge($response, $dbRow);
		exit(json_encode($response));
		break;
	// 团购配置
	case 'set_conf':

		$signkey     = htmlspecialchars($_REQUEST['sign']);
		$cperWay     = htmlspecialchars($_REQUEST['cooperation_way']);
		$identity    = htmlspecialchars($_REQUEST['Identity']);
		$insTime     = date('Y-m-d H:i:s');
		$DockingMode = $_REQUEST['conf_type'] + 0; // 0 去哪儿 1 美团  2 百度直达

		$push_land_f = 1 ;
		if(count($_REQUEST['ids'])){

			foreach($_REQUEST['ids'] as $tid=>$id){
				if($id=='') continue;
				$sql = "select * from uu_qunar_use where tid_aid='$id' and DockingMode=$DockingMode limit 1"; 
				$GLOBALS['le']->query($sql);
				if($GLOBALS['le']->fetch_assoc()) {
					$push_land_f = 0;
					unset($_REQUEST['ids'][$tid]);
					continue;// 存配置则忽略
				}
				
				$id = htmlspecialchars($id);
				$ins = "insert into uu_qunar_use (tid_aid,supplierIdentity,signkey,fid,cooperation_way,itime,DockingMode,tid) values ('$id','$identity','$signkey',$memberSID,'$cperWay','$insTime', $DockingMode, $tid)";
				$GLOBALS['le']->query($ins);
			}
		}
		
		if($DockingMode==1 || $DockingMode==2){// 美团推送
			
			$url = 'http://10.160.4.140/new/d/';
			$url.= ($DockingMode==1) ? 'meituan/MT_PushDeal.php?':'module/api/bd_zhidahao/bdzdh_pushGoods.php?';
			$params['signkey']       = $signkey;
			$params['partnerId']     = $identity;
			$params['push_land_f']   = $push_land_f;// 是否推送景区信息
			$params['partnerPoiId']  = $identity;
			$params['partnerDealId'] = array_filter($_REQUEST['ids']);
			@file_get_contents($url.http_build_query($params));
		}
		
		exit('{"status":"success","msg":"配置成功"}');
		break;
		
	// 删除配置
	case 'remove':
		
		$uid = $_REQUEST['id']+0;
		if($uid==0) exit('{"status":"fail","msg":"参数错误"}');
		$sql = "select * from uu_qunar_use where id=$uid and fid=$memberSID limit 1";
		$GLOBALS['le']->query($sql);
		$u_info = $GLOBALS['le']->fetch_assoc();
		$u_info['a_name'] = $_SESSION['memberID'];
		
		$sql = "delete from uu_qunar_use where id=$uid and fid=$memberSID limit 1";
		if($GLOBALS['le']->query($sql)){
			include '/var/www/html/new/d/class/abc/Request.class.php';
			Request::Fsockopen_Zero_Wait('http://10.160.4.140/new/d/module/api/api_product_changenotice/Product_change_cancel.php', $u_info);
			exit('{"status":"success","msg":"删除成功"}');
		}
		exit('{"status":"fail","msg":"删除失败"}');
		break;
	default:break;
	
	
	
	
	
}